<!--
 * @Description: 采购审批
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:30:17
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main>
        <div class="tabtop">
          <div v-for="(item, index) in contractTypelist" :key="index" @click="choose(item)">
            <div :class="currenindex == index ? 'active' : 'text'">{{ item.value }}</div>
            <div v-if="currenindex !== index && currenindex !== index + 1 && index !== 2" class="hr"></div>
          </div>
        </div>
        <div class="header_right" @click="showCardNav = !showCardNav">
          <div class="title">搜索</div>
          <div>
            <div :class="{ 'arrowTransform': !showCardNav, 'arrowTransformReturn': showCardNav}">
              <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
            </div>
          </div>
        </div>
        <div v-show="showCardNav" class="hr"></div>
        <el-collapse-transition>
          <div v-show="showCardNav">
            <div class="search">
              <span style="display: inline-block;margin-bottom: 10px;">
                <span style="margin-right: 12px;">站点名称</span>
                <el-input v-model="tableParam.station" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData(),QueryStatisticsFun()" />
              </span>
              <span style="margin-left: 24px;">
                <span style="margin-right: 12px;">原物料名称</span>
                <el-input v-model="tableParam.materials" style="width: 240px;" clearable placeholder="请输入" @keyup.enter.native="gettableData(),QueryStatisticsFun()" />
              </span>
              <el-button icon="el-icon-search" size="medium" class="bottom_all but1" @click="(tableParam.page = 1), gettableData(),QueryStatisticsFun()">查 询</el-button>
              <el-button size="medium" class="bottom_all_two" style="margin-left:12px;" @click="init()">重 置</el-button>
            </div>
          </div>
        </el-collapse-transition>
        <div class="hr"></div>
        <div class="card" style="padding-top:10px">
          <div class="card_nav">
            <div>
              <el-button size="small" class="bottom_all" style="margin-left: 0" :disabled="selectionList.length==0" @click="pass()">
                审批
              </el-button>
              <el-button size="small" class="bottom_two" :disabled="selectionList.length==0" @click="contect='',nopass()">
                驳回
              </el-button>
              <el-button v-if="currenindex==0" size="small" class="bottom_one" @click="dialog=true">
                查看统计
              </el-button>
            </div>
          </div>
          <div v-loading="tableLoading" class="card_info" :style="style">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" :selectable="selectableFun" fixed="left">
              </el-table-column>
              <template v-for="(item, index2) in table">
                <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :width="item.width">
                  <template slot-scope="scope">
                    <div v-if="item.label == '状态'">{{scope.row.planStatus==2?'待审核':scope.row.planStatus==3?'已通过':'已驳回'}}</div>
                    <el-button v-else-if="item.label == '供应详情'" size="mini" class="bottom_one" @click="showdetails(scope.row)">供应详情</el-button>
                    <!-- <div v-else-if="item.label == '操作'">
                      <el-button v-if="scope.row.planStatus==2&&ButtonList.findIndex(res=>(res.buttonValue=='TONGGUO'))!==-1" size="mini" class="bottom_one" @click="pass(scope.row)">通过</el-button>
                      <el-button v-if="scope.row.planStatus==2&&ButtonList.findIndex(res=>(res.buttonValue=='BOHUI'))!==-1" size="mini" class="bottom_one" @click="contect='',nopass(scope.row)">驳回</el-button>
                    </div> -->
                    <span v-else>{{ scope.row[item.prop] }}</span>
                  </template>
                </el-table-column>
              </template>
            </el-table>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 查看详情 -->
    <el-dialog v-dialogDrag :visible.sync="detailsDialog" width="1045px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">查看详情</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="list" tooltip-effect="dark">
          <el-table-column label="合同编号" align="center" prop="contractNo"></el-table-column>
          <el-table-column label="原物料供应商" align="center" prop="supplierName"></el-table-column>
          <el-table-column label="原物料" align="center" prop="rawName"></el-table-column>
          <el-table-column label="规格" align="center" prop="specification"></el-table-column>
          <el-table-column label="品牌" align="center" prop="brand"></el-table-column>
          <el-table-column label="份额" align="center" prop="supplierPercent"><template slot-scope="scope">
              {{list.length===1?100:scope.row.supplierPercent}}%
            </template>
          </el-table-column>
          <el-table-column label="是否含运输" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.transportStatus==1" style="color:#00A754;">是</span>
              <span v-else style="color:#969799;">否</span>
            </template>
          </el-table-column>
          <el-table-column label="需求量" align="center" prop="planNumber"></el-table-column>
          <el-table-column label="采购量" align="center" prop="supplierNumber"></el-table-column>
          <el-table-column label="车辆外包合同" align="center" prop="carContractNo"></el-table-column>
          <el-table-column label="车辆供应商" align="center" prop="carCompanyName"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="detailsDialog=false">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 驳回 -->
    <el-dialog v-dialogDrag :visible.sync="nopassDailog" width="580px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">驳回</span>
      <div class="dialoginfo">
        <el-form :inline="true" label-width="90px">
          <el-form-item prop="code">
            <span slot="label">驳回原因：</span>
            <el-input v-model="contect" type="textarea" :rows="5" resize="none" placeholder="请输入" style="width:400px" maxlength="60" show-word-limit clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="nopassDailog=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px;" @click="submitNopass()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 查看统计 -->
    <el-dialog v-dialogDrag :visible.sync="dialog" width="880px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">查看统计</span>
      <div class="dialoginfo">
        <div style="padding-right:10px;max-height:530px" class="scroll">
          <h3>供应采购排名</h3>
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="zongList" tooltip-effect="dark">
            <el-table-column align="center" label="供应商名称" prop="name"></el-table-column>
            <el-table-column align="center" label="采购总量" prop="account">
              <template slot-scope="scope">{{scope.row.account}} 吨</template>
            </el-table-column>
          </el-table>
          <div class="combined">小计：{{zong}}</div>
        </div>
        <div style="padding-left:10px">
          <h3>原料品牌排名</h3>
          <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="zongList1" tooltip-effect="dark">
            <el-table-column align="center" label="原物料品牌" prop="name"></el-table-column>
            <el-table-column align="center" label="需求总量" prop="account">
              <template slot-scope="scope">{{scope.row.account}} 吨</template>
            </el-table-column>
          </el-table>
          <div class="combined">小计：{{zong1}}</div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog=false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import { queryPage, getPlanDetail, okOrTurnDown, QueryStatistics } from "@/api/GHnumber/DSP.js";
export default {
  mixins: [mixin],
  data() {
    return {
      dialog: false,
      selectionList: [],
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [
        { label: "公司", width: "120", prop: "companyName", status: true },
        { label: "站点名称", width: "120", prop: "station", status: true },
        { label: "原料名称", width: "auto", prop: "materials", status: true },
        {
          label: "理论需求量",
          width: "auto",
          prop: "theoryNumber",
          status: true,
        },
        { label: "库存缺口量", width: "120", prop: "inventory", status: true },
        {
          label: "实际需求量",
          width: "auto",
          prop: "practiceNumer",
          status: true,
        },
        {
          label: "采购比例%",
          width: "auto",
          prop: "purchaseRatio",
          status: true,
        },
        { label: "采购量", width: "auto", prop: "purchaseNum", status: true },
        { label: "供应详情", width: "120", prop: "", status: true },
        { label: "申请日期", width: "auto", prop: "applyTime", status: true },
        { label: "需求日期", width: "120", prop: "needDate", status: true },
        { label: "状态", width: "120", prop: "", status: true },
        // { label: "操作", width: "120", prop: "", status: true },
      ],
      /*表单页类型，0为无树状，1为有树状，有树状在el-main加上display:flex*/
      pagesType: 0,
      /*添加表单数据*/
      contractTypelist: [
        // { value: "全部", id: 0, index: 0 },
        { value: "待审核", id: 0, index: 2 },
        { value: "已审核", id: 1, index: 3 },
        { value: "已驳回", id: 2, index: 4 },
      ],
      currenindex: 0,
      detailsDialog: false,
      list: [],
      low: {},
      nopassDailog: false,
      /*驳回*/
      contect: "",
      zong: '',
      zongList: [],
      zong1: '',
      zongList1: [],
    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = {
      ...this.tableParam,
      planStatus: 2,
      stationId: "",
      materialsId: "",
    };
    this.gettableData();
    this.QueryStatisticsFun()
  },
  /*
   *copy(data)深拷贝数据,返回拷贝完的数据
   *gettableData获取列表数据
   *load下载
   *SortNum保持序列号
   * UpdateOrDelete禁用，启用，删除
   * submitFromDate保存更新数据
   */
  methods: {
    QueryStatisticsFun() {
      this.zong = ''
      this.zongList = []
      this.zong1 = ''
      this.zongList1 = []
      QueryStatistics(this.tableParam).then((res) => {
        this.zongList = res.data.supplierNameList
        this.zong = res.data.sumSupplier
        this.zong1 = res.data.sumBrand
        this.zongList1 = res.data.brandList
      })
    },
    init() {
      /*重置数据*/
      this.tableParam.station = "";
      this.tableParam.materials = "";
      this.gettableData();
      this.QueryStatisticsFun()
    },
    choose(a) {
      this.currenindex = a.id;
      this.tableParam.planStatus = a.index;
      this.tableParam.page = 1;
      this.gettableData();
      this.QueryStatisticsFun()
    },
    showdetails(low) {
      this.detailsDialog = true;
      getPlanDetail({ planId: low.id }).then((res) => {
        this.list = res.data;
        this.console(res.data);
      });
    },
    pass() {
      this.$confirm("此操作将通过该需求?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        cancelButtonClass: "bottom_all_two",
        confirmButtonClass: "bottom_all",
        type: "warning",
      }).then(() => {
        let arr = []
        this.selectionList.forEach((v) => {
          arr.push({ id: v.id, planStatus: 3 })
        })
        okOrTurnDown(arr).then((res) => {
          if (res.code === 1001) {
            this.gettableData();
            this.QueryStatisticsFun();
            this.$message.success('已通过');
          }
        });
      })
    },
    nopass(low) {
      this.low = low;
      this.nopassDailog = true;
    },
    submitNopass() {
      let arr = []
      this.selectionList.forEach((v) => {
        arr.push({
          id: v.id,
          planStatus: 4,
          remark: this.contect,
        })
      })
      okOrTurnDown(arr).then((res) => {
        if (res.code === 1001) {
          this.gettableData();
          this.QueryStatisticsFun()
          this.nopassDailog = false;
          this.$message.success('驳回成功！！')
        }
      });
    },
    handleSelectionChange(val) {
      this.selectionList = val
    },
    selectableFun(row) {
      if (row.planStatus == 2) {
        return true
      } else {
        return false
      }
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    },
  },
};
</script>

<style lang="scss" scoped>
.combined {
  border: 1px solid #ebeef5;
  text-align: center;
  line-height: 40px;
}
.dialoginfo {
  display: flex;
  padding: 0 20px;
  max-height: 530px;
  > div {
    flex: 1;
  }
}
.el-input,
.el-select {
  width: 240px;
}
.table_link {
  margin-left: 10px;
  color: $bg_color;
}

.table_link:hover {
  opacity: 0.8;
}
.tabtop {
  width: 571px;
  display: flex;
  border: $bg_color 1px solid;
  border-radius: 4px;
  margin: 20px 20px 0 20px;
  > div {
    height: 40px;
    width: 190px;
    font-size: 16px;
    font-weight: 400;
    cursor: pointer;
    display: flex;
    align-items: center;
    .text {
      width: 188px;
      @include discen;
      line-height: 40px;
      color: $bg_color;
    }
    .active {
      width: 189px;
      @include discen;
      line-height: 40px;
      color: #ffffff;
      background: $bg_color;
      border-radius: 4px;
    }
    .hr {
      height: 20px;
      width: 2px;
      background: $bg_color;
    }
  }
}
.ZL {
  padding: 0 20px;
  color: #666;
  > div {
    padding-left: 50px;
    > div {
      margin-bottom: 5px;
    }
  }
}
</style>
